import { useTable, LIST_TYPE } from '@crud/index';
import { toolOptions2Map } from '@/utils';
import { getList } from '@/api/crm-dyj/course';

// 课程类型
export const classifyOptions: any = [
  { label: '全部', value: 0 },
  { label: '产品功能', value: 1 },
  { label: '投放技巧', value: 2 },
  { label: '抖音玩法', value: 3 }
];

// 成长阶段
export const stageOptions: any = [
  { label: '全部', value: 0 },
  { label: '新手入门', value: 1 },
  { label: '成长进阶', value: 2 },
  { label: '成熟突破', value: 3 }
];
// 课程状态
export const statusOptions: any = [
  { label: '全部', value: '' },
  { label: '已上架', value: 1 },
  { label: '已下架', value: 0 }
];

// 课程类型字典
export const classifyMap: any = toolOptions2Map(classifyOptions);
// 成长阶段字典
export const stageMap: any = toolOptions2Map(stageOptions);
// 状态字典
export const statusMap: any = toolOptions2Map(statusOptions);

// 表格
export const useTableList = (options: any = {}) => {
  const columns = [
    { label: '课程标题', prop: 'title', minWidth: 200, ellipsis: true, showOverflowTooltip: true },
    { label: '课程链接', prop: 'course_url', width: 220, render: 'course_url' },
    { label: '课程类型', prop: 'classify', minWidth: 120, align: 'center', render: (s: any) => classifyMap[s.row.classify] },
    { label: '成长阶段', prop: 'stage', minWidth: 120, render: (s: any) => stageMap[s.row.stage] },
    { label: '创建时间', prop: 'create_time', minWidth: 177, type: 'dateTime' },
    { label: '浏览数', prop: 'views', minWidth: 120, render: (s: any) => s.row.views ?? '-' },
    { label: '课程状态', prop: 'status', minWidth: 120, render: (s: any) => statusMap[s.row.status] },
    { label: '操作', align: 'center', render: 'actions', width: 220, fixed: 'right' }
  ];

  return useTable({
    type: LIST_TYPE.CONTENT,
    params: {
      // type: 1,
      title: undefined
    },
    getParams: (params) => {
      return {
        ...params
        // ...formatParamsSelectVal([['send_object', '']], params)
      };
    },
    columns,
    getList
  });
};
